import { useSelector, useDispatch } from 'react-redux';
import { increment, decrement } from './store/actions/counter';

import Child from './Child';

function App() {
  // 创建dispatch
  const dispatch = useDispatch();

  // 从store中选取数据
  const data = useSelector((state) => state.counter);
  // console.log('data', data);
  const todos = useSelector((state) => state.todos);
  // console.log('todos', todos);

  // 事件处理函数
  const handleIncrement = () => {
    dispatch(increment(3));
  };
  // 减少
  const handleDecrement = () => {
    dispatch(decrement(1));
  };

  return (
    <div>
      <h3>{data}</h3>
      <button onClick={handleIncrement}>+</button>
      <button onClick={handleDecrement}>-</button>
      <hr />
      <Child />
    </div>
  );
}

export default App;
